home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / perlnt.zip / registry.txt < prev    next >
Text File  |  1993-07-25  |  10KB  |  279 lines

  1. -----------------------------------------------------------------------------
  2. Registry.txt
  3. -----------------------------------------------------------------------------
  4.  
  5. This file documents the extentions to Perl for NT that allow perl
  6. scripts access to the NT registry database. All Registry API's have
  7. been duplicated as user defined perl subroutines, with the exception
  8. of RegNotifyChangeKeyValue. This routine was not implemented due to
  9. time constraints and due to it's usefulness in perl scripts not being
  10. immediately apparent. It may be implemented in the future.
  11.  
  12. IMPORTANT NOTE: It is possible to make your system unbootable by
  13. corrupting the registry database! Use EXTREME caution when writing a
  14. perl script that updates the registry! Also note that none of the
  15. routines that actually modify the files that comprise the registry
  16. have been tested. Only the routines that read or write keys/values in
  17. the existing registry have been tested.
  18.  
  19. The Perl registry access subroutines nearly duplicate the Win32 API
  20. for registry calls.  Although they are not perl-like, it was felt that
  21. the perl calls should look as nearly like the documentation provided
  22. with NT as possible. Hopefully this will minimize confusion when using
  23. them.
  24.  
  25. The main difference between the C registry routines and the perl
  26. versions of them is that whenever a size option is specified as an
  27. argument to a C routine, that parameter is omitted from the perl
  28. version, since perl already knows how big a scalar is and will
  29. dynamically size a parameter used to return a value.
  30.  
  31. Note that all arguments to the perl registry routines are SCALARS.
  32. Passing in arrays to the enumeration functions would be convienent, so
  33. that it would not be nessesary to iterate when enumerating keys or
  34. values, but again, time constraints interferred. This feature may be
  35. implemented in a later release.
  36.  
  37. Some routines are documented in the Win32 API help file as having been
  38. provided only for Windows 3.1 compatiblity. These routines include
  39. RegCreateKey, RegOpenKey, RegEnumKey, RegQueryValue, and RegSetValue.
  40. All of these routines have new versions with "Ex" appended to their
  41. names which are the preferred version for use in new applications. In
  42. implementing these routines in the Perl interpreter, all calls were
  43. made to the new and improved versions of these routines so that
  44. compatibility problems will be avoided when Microsoft upgrades
  45. software. So, a perl script making the call:
  46.  
  47.     &RegOpenKey($HKEY_LOCAL_MACHINE, "SOFTWARE\\Intergraph", $h);
  48.  
  49. actually boils down to a call to RegOpenKeyEx with appropriate
  50. defaults in the perl interpreter. 
  51.  
  52. For more information on the contents of the registry and on accessing
  53. the registry, see the help file for the registry editor (RegEdit), the
  54. API documentation in the Win32 API help file, and the Microsoft
  55. Windows NT Resource Guide (Preliminary March 1993).
  56.  
  57.    Conventions:
  58.  
  59.         $hkey: refers to a key handle value. Either one of the
  60.                predefined variables or a value returned from 
  61.                RegOpenKey[Ex] or RegCreateKey[Ex].
  62.  
  63.         $newhkey: the parameter where a new handle will be returned.
  64.  
  65.         $subkey: a string used as a subkey of the specified key
  66.                  handle.
  67.  
  68.         $sam: a security access mask (on of the $KEY_* variables).
  69.  
  70.         $valname: a scalar that either specifies a value name or
  71.                   receives a value name.
  72.  
  73.         $index: a unsigned integer used when enumerating subkeys or
  74.                 values of a key.
  75.  
  76.         $reserved: a parameter that Microsoft has reserved for future
  77.                    use. Should be zero, but in fact is ignored.
  78.  
  79.     All of the Registry access routines return a success or failure
  80.     status with the actual return value from the routine in $!. This
  81.     allows you to write code such as this:
  82.  
  83.         $keystring = "SOFTWARE\\Description\\Intergraph\\Perl";
  84.         &RegCreateKey($HKEY_LOCAL_MACHINE, $keystring, $newhkey) ||
  85.                 die "Can't open $keystring: $!\n";
  86.  
  87.     If the call to RegCreateKeyEx fails then it's error code is
  88.     stored in $!. The failure status causes the die routine to be
  89.     called which prints the string corresponding to the error number
  90.     and then terminates the perl process.
  91.  
  92.  
  93.  
  94. Variables:
  95.  
  96.     $LoginName - login name of current user
  97.     $NodeName - network name of local machine
  98.  
  99.     Pre-defined key handles
  100.  
  101.     $HKEY_CLASSES_ROOT
  102.     $HKEY_CURRENT_USER
  103.     $HKEY_LOCAL_MACHINE
  104.     $HKEY_USERS
  105.  
  106.     Security Access Mask values
  107.  
  108.     $KEY_ALL_ACCESS
  109.     $KEY_CREATE_SUB_KEY
  110.     $KEY_ENUMERATE_SUB_KEYS
  111.     $KEY_EXECUTE
  112.     $KEY_NOTIFY
  113.     $KEY_QUERY_VALUE
  114.     $KEY_READ
  115.     $KEY_SET_VALUE
  116.     $KEY_WRITE
  117.  
  118.     Data types from the registry
  119.  
  120.     $REG_BINARY  - binary data
  121.     $REG_DWORD - 32 bit value
  122.     $REG_DWORD_LITTLE_ENDIAN - 32 bit value in little endian byte order
  123.     $REG_DWORD_BIG_ENDIAN - 32 bit value in big endian (network) byte order
  124.     $REG_EXPAND_SZ - null terminated string with environment variables
  125.     $REG_LINK - symbolic link within registry
  126.     $REG_MULTI_SZ - multiple null terminated strings
  127.     $REG_NONE - no type associated with this value
  128.     $REG_RESOURCE_LIST - device resource list
  129.     $REG_SZ - null terminated string
  130.  
  131.  
  132. Subroutines:
  133.  
  134. &RegCloseKey ($hkey)
  135.     $hkey - an open key handle from a call to RegCreateKey,
  136.             RegCreateKeyEx, RegOpenKey, or RegOpenKeyEx. 
  137.  
  138. &RegConnectRegistry ($machine, $hkey, $newhkey)
  139.     $machine - name of an NT system.
  140.     $hkey - one of $HKEY_LOCAL_MACHINE or $HKEY_USERS.
  141.     $newkey - new handle for access on remote machine.
  142.  
  143. &RegCreateKey ($hkey, $subkey, $newhkey)
  144.     $hkey - open key handle.
  145.     $subkey - string value specifying subkey of currently open key.
  146.     $newhkey - new handle.
  147.  
  148. &RegCreateKeyEx ($hkey, $subkey, $reserved, $class, $options, $sam,
  149.                  $SecAttrib, $newhkey, $disposition)
  150.     $hkey - open key handle.
  151.     $subkey - string identifying the subkey to create/open
  152.     $reserved - ignored
  153.     $class - class name for new key
  154.     $options - indicates if new key is volatile or not
  155.     $sam - security access mask.
  156.     $SecAttrib - security attributes structure (packed data)
  157.     $newhkey - new handle.
  158.     $disposition - 
  159.  
  160. &RegDeleteKey ($hkey, $subkey)
  161.     $hkey - open key handle
  162.     $subkey - string identifying the subkey to delete
  163.  
  164. &RegDeleteValue ($hkey, $valname);
  165.     $hkey - open key handle
  166.     $valname - name of value to delete
  167.  
  168. &RegEnumKey ($hkey, $index, $subkey)
  169.     $hkey - open key handle
  170.     $index - numeric index of key to enumerate
  171.     $subkey - returned key name
  172.  
  173. &RegEnumKeyEx ($hkey, $index, $subkey, $reserved, $class, $time)
  174.     $hkey - open key handle
  175.     $index - numeric index of key to enumerate
  176.     $subkey - returned key name
  177.     $reserved - must be zero
  178.     $class - returned class name of $subkey
  179.     $time - time of last modification of $subkey
  180.     
  181. &RegEnumValue ($hkey, $index, $valname, $reserved, $type, $data)
  182.     $hkey - open key handle
  183.     $index - numeric index of key to enumerate
  184.     $valname - returned value name
  185.     $reserved - must be zero
  186.     $type - returned type of $valname
  187.     $data - data associated with $valname (of data type $type)
  188.  
  189. &RegFlushKey ($hkey)
  190.     $hkey - open key handle
  191.  
  192. &RegGeyKeySecurity ($hkey, $SecInf, $SecDesc)
  193.     $hkey - open key handle
  194.     $SecInf - Security information structure (packed)
  195.     $SecDesc - returned Security Descriptor data (packed)
  196.  
  197. &RegLoadKey ($hkey, $subkey, $file)
  198.     $hkey - open key handle
  199.     $subkey - string identifying subkey of $key
  200.     $file - string identifying filename to load information from
  201.  
  202. &RegOpenKey ($hkey, $subkey, $newhkey)
  203.     $hkey - open key handle
  204.     $subkey - string identifying subkey of $key
  205.     $newhkey - returned key handle
  206.     
  207. &RegOpenKeyEx ($hkey, $subkey, $reserved, $sam, $newhkey)
  208.     $hkey - open key handle
  209.     $subkey - string identifying subkey of $key
  210.     $reserved - must be zero
  211.     $sam - requested security access mask
  212.     $newhkey - returned key handle
  213.  
  214. &RegQueryInfoKey ($hkey, $class, $reserved, $nsubkeys, $maxsubkey, 
  215.                   $maxclass, $nvalues, $maxvalname, $maxvaldata,
  216.                   $SecDesc, $time)
  217.     $hkey - open key handle
  218.     $class - returned key class (string)
  219.     $reserved - must be zero
  220.     $nsubkey - number of subkeys for this key
  221.     $maxsubkey - size of largest subkey
  222.     $maxclass - size of largest class name
  223.     $nvalues - number of values associated with this key
  224.     $maxvalname - size of largest value name
  225.     $manvaldata - size of largest value data
  226.     $SecDesc - Security Descriptor (packed data)
  227.     $time - time of last write
  228.  
  229. &RegQueryValue ($hkey, $subkey, $value)
  230.     $hkey - open key handle
  231.     $subkey - string identifying the subkey of key to query
  232.     $value - returned value for first NULL valname
  233.  
  234. &RegQueryValueEx ($hkey, $valname, $reserved, $type, $data)
  235.     $hkey - open key handle
  236.     $valname - string identifying value to retreive
  237.     $reserved - must be zero
  238.     $type - returned type of $data
  239.     $data - returned data associated with $valname
  240.  
  241. &RegReplaceKey ($hkey, $subkey, $newfile, $oldfile)
  242.     $hkey - open key handle
  243.     $subkey - string identifying subkey of $key
  244.     $newfile - file to put into registry
  245.     $oldfile - name for old registry file
  246.  
  247. &RegRestoreKey ($hkey, $file, $flags)
  248.     $hkey - open key handle
  249.     $file - name of file to restore key from
  250.     $flags - indicates if key data is volatile
  251.  
  252. &RegSaveKey ($hkey, $file, $SecAttrib)
  253.     $hkey - open key handle
  254.     $file - file in which to save key and subkeys.
  255.     $SecAttrib - security attributes for new file (packed data)
  256.  
  257. &RegSetKeySecurity ($hkey, $SecInf, $SecDesc);
  258.     $hkey - open key handle
  259.     $SecInf - Security Information structure (packed data)
  260.     $SecDesc - Security Descriptor structure (packed data)
  261.  
  262. &RegSetValue ($hkey, $subkey, $type, $data)
  263.     $hkey - open key handle
  264.     $subkey - string indentifying subkey 
  265.     $type - data type of $data
  266.     $data - data to associate with $subkey (NULL name)
  267.  
  268. &RegSetValueEx ($hkey, $valname, $reserved, $type, $data)
  269.     $hkey - open key handle
  270.     $valname - name of value to set
  271.     $reserved - must be zero
  272.     $type - data type of $data
  273.     $data - data to associate with valname
  274.  
  275. &RegUnLoadKey ($hkey, $subkey)
  276.     $hkey - open key handle
  277.     $subkey - string that identifies subkey tree to be unloaded
  278.  
  279.